package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.UpdateInterceptor;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaUpdate;
import com.meida.module.bus.client.enums.BalanceLogTypeEnum;
import com.meida.module.pay.client.entity.PayCashout;
import com.meida.module.pay.provider.service.PayConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 后台提现审核
 */
@Component
public class PayCashOutCheckHandler implements UpdateInterceptor<PayCashout> {
    @Autowired
    private PayConfigService payConfigService;

    @Override
    public ResultBody validate(CriteriaUpdate cu, EntityMap params) {
        Integer checkState = params.getInt("checkState");
        if (checkState == 2) {
            String reason = params.get("reason");
            if (FlymeUtils.isEmpty(reason)) {
                return ResultBody.failed("请填写驳回原因");
            }
        }
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaUpdate cu, EntityMap params, PayCashout payCashout) {
    }

    @Override
    public void complete(CriteriaUpdate cu, EntityMap params, PayCashout payCashout) {
        Long cashoutId = payCashout.getCashoutId();
        Integer status = payCashout.getStatus();
        if (status == 1) {
            payConfigService.doCashout(cashoutId, BalanceLogTypeEnum.logType4.getValue(), "");
        }

    }
}
